package com.zjy.business.system.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjy.business.system.domain.entity.SysOperationLog;
import com.zjy.business.system.domain.manager.query.ManagerListPageSysOperationQuery;
import com.zjy.business.system.domain.manager.vo.ManagerListPageSysOperationVo;
import com.zjy.business.system.mapper.SysOperationLogMapper;
import com.zjy.common.utils.ConvertBeanUtils;
import com.zjy.log.event.OperationLogEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zjy
 * @since 2024-10-22
 */
@Service
public class SysOperationLogDao extends ServiceImpl<SysOperationLogMapper, SysOperationLog> {

    /**
     * 操作日志记录
     */
    @Async
    @EventListener
    public void recordOperationLog(OperationLogEvent event) {
        SysOperationLog log = ConvertBeanUtils.convert(event, SysOperationLog.class);
        save(log);
    }

    /**
     * 分页查询操作日志
     * @param query
     * @return
     */
    public List<ManagerListPageSysOperationVo> listPageSysOperation(ManagerListPageSysOperationQuery query) {
        return this.baseMapper.listPageSysOperation(query);
    }
}
